package com.aigou.admin.dao.impl;

import com.aigou.admin.utils.JDBCUtils;
import com.aigou.admin.dao.OrderProductDao;
import com.aigou.admin.entity.OrderProduct;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: xsc_hunter
 * @Date: 2024/12/4) 下午2:22
 * @Version: 1.0
 */

@Repository
public class OrderProductDaoImpl implements OrderProductDao {
    @Override
    public List<OrderProduct> selectAll() {
        return JDBCUtils.executeQuery(OrderProduct.class, "select * from s_order_product");
    }

    @Override
    public OrderProduct selectById(String id) {
        List<OrderProduct> OrderProduct = JDBCUtils.executeQuery(OrderProduct.class, "select * from s_order_product where id = ? ",  id);
        if (OrderProduct.isEmpty()) {
            return null;
        }
        return OrderProduct.get(0);
    }

    @Override
    public Boolean insert(OrderProduct orderProduct) {
        int rows = JDBCUtils.executeUpdate("insert into s_order_product(id,order_id,product_id,product_num) values(?,?,?,?)",
                orderProduct.getId(),orderProduct.getProduct_Id(),orderProduct.getProduct_Num());
        return rows > 0;
    }

    @Override
    public Boolean update(OrderProduct orderProduct) {
        int rows = JDBCUtils.executeUpdate("update s_order_product set id=?,order_id=?,product_id=?,product_num=? where id = ?",
                orderProduct.getId(),orderProduct.getProduct_Id(),orderProduct.getProduct_Num());
        return rows > 0;
    }

    @Override
    public Boolean delete(String id) {
        int rows = JDBCUtils.executeUpdate("delete from s_order_product where id = ?", id);
        return rows >0;
    }
}
